﻿namespace jzgl.Windows
{
    using jzgl.Controller;
    using jzgl.Model;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class SysUsers : Form
    {
        private Button btn_Add_Edit;
        private Button btn_Cancel;
        private Button btn_ShanChu;
        private Button btn_ShouQuan;
        private Button btn_TianJia;
        private Button btn_XiuGai;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private ComboBox comboBox1;
        private IContainer components = null;
        private DataGridView dataGridView1;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
        private Designer des = new Designer();
        private DesignerDB desDB = new DesignerDB();
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private GroupBox groupBox3;
        private Label label1;
        private Label label3;
        private Label label4;
        private Label label5;
        private BudgetListDB listDB = new BudgetListDB();
        private string name = "";
        private Panel panel1;
        private int t = 0;
        private DataTable table = null;
        private TextBox txt_Remark;
        private TextBox txt_user_Pwd;
        private TextBox txt_UserFullName;
        private TextBox txt_UserName;
        private SysUser user = new SysUser();
        private SysUserDB userDB = new SysUserDB();

        public SysUsers()
        {
            this.InitializeComponent();
            base.Height = 300;
            this.Data_Bind();
            this.groupBox3.Visible = false;
        }

        private void btn_Add_Edit_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txt_UserName.Text.Trim().Equals(""))
                {
                    MessageBox.Show("用户名不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (this.txt_UserFullName.Text.Trim().Equals(""))
                {
                    MessageBox.Show("请填写设计师姓名！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (this.comboBox1.Text.Trim().Contains("请选择"))
                {
                    MessageBox.Show("请选择权限组！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    int num;
                    int num2;
                    this.des._DesignerRemark = this.user._UserName = this.txt_UserName.Text.Trim();
                    this.des._DesignerName = this.user._UserFullname = this.txt_UserFullName.Text.Trim();
                    this.user._UserGroup = this.comboBox1.Text.Trim();
                    this.user._UserRemark = this.txt_Remark.Text.Trim();
                    if (this.t == 1)
                    {
                        if (this.userDB.Is_UserExistBY_Name(this.user) != 0)
                        {
                            MessageBox.Show("该用户名已经存在！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        this.txt_user_Pwd.Text = "1234";
                        if (this.txt_user_Pwd.Text.Trim().Equals(""))
                        {
                            MessageBox.Show("密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        this.user._UserPassword = "1234";
                        num = this.userDB.Add_SysUser(this.user);
                        num2 = this.desDB.Add_Designer(this.des);
                        this.Data_Bind();
                        this.t = 0;
                    }
                    if (this.t == 2)
                    {
                        num = this.userDB.Update_SystemUser(this.user);
                        num2 = this.desDB.Update_Designer_2(this.des, this.name);
                        this.listDB.Update_BudgetList_DesName(this.txt_UserFullName.Text.Trim(), this.name);
                        this.Data_Bind();
                        this.name = "";
                        this.t = 0;
                    }
                    base.Height = 300;
                    this.groupBox2.Visible = true;
                    this.dataGridView1.Enabled = true;
                    this.groupBox3.Visible = false;
                    this.dataGridView1.Enabled = true;
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            try
            {
                base.Height = 300;
                this.groupBox2.Visible = true;
                this.groupBox3.Visible = false;
                this.dataGridView1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }

        private void btn_ReSet_Click(object sender, EventArgs e)
        {
        }

        private void btn_ShanChu_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("确定要删除吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                {
                    if (this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim().Equals("admin"))
                    {
                        MessageBox.Show("系统默认用户不能删除！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        this.user._UserName = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                        int num = this.userDB.Delete_SysUser(this.user);
                        int num2 = this.desDB.Delete_Designer2(this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim());
                        this.Data_Bind();
                    }
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShouQuan_Click(object sender, EventArgs e)
        {
        }

        private void btn_ShuaXin_Click(object sender, EventArgs e)
        {
            try
            {
                this.Data_Bind();
            }
            catch (Exception)
            {
            }
        }

        private void btn_TianJia_Click(object sender, EventArgs e)
        {
            try
            {
                this.t = 1;
                base.Height = 0x189;
                this.txt_UserName.ReadOnly = false;
                this.txt_user_Pwd.ReadOnly = false;
                this.groupBox2.Visible = false;
                this.groupBox3.Visible = true;
                this.dataGridView1.Enabled = false;
                this.txt_UserName.Text = this.txt_UserFullName.Text = this.txt_Remark.Text = this.txt_user_Pwd.Text = "";
                this.comboBox1.Text = " --请选择--";
            }
            catch (Exception)
            {
            }
        }

        private void btn_XiuGai_Click(object sender, EventArgs e)
        {
            try
            {
                this.t = 2;
                base.Height = 0x189;
                this.groupBox2.Visible = false;
                this.groupBox3.Visible = true;
                this.txt_UserName.ReadOnly = true;
                this.txt_user_Pwd.ReadOnly = true;
                this.txt_UserName.Text = this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index].Cells[0].Value.ToString();
                this.name = this.txt_UserFullName.Text = this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index].Cells[1].Value.ToString();
                this.txt_Remark.Text = this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index].Cells[3].Value.ToString();
                this.comboBox1.Text = this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index].Cells[2].Value.ToString();
                if (this.txt_UserName.Text.Trim().Equals("admin"))
                {
                    this.comboBox1.Enabled = false;
                }
                else
                {
                    this.comboBox1.Enabled = true;
                }
            }
            catch (Exception)
            {
            }
        }

        public void Data_Bind()
        {
            try
            {
                this.dataGridView1.Rows.Clear();
                this.table = this.userDB.Show_SysUser();
                if (this.table != null)
                {
                    for (int i = 0; i < this.table.Rows.Count; i++)
                    {
                        object[] values = new object[] { this.table.Rows[i][1].ToString(), this.table.Rows[i][2].ToString(), this.table.Rows[i][4].ToString(), this.table.Rows[i][5].ToString() };
                        this.dataGridView1.Rows.Add(values);
                    }
                }
                this.txt_UserName.Text = "";
                this.txt_UserFullName.Text = "";
                this.txt_Remark.Text = "";
                this.txt_user_Pwd.Text = "";
                this.comboBox1.Text = " --请选择--";
            }
            catch (Exception)
            {
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.txt_UserName.Text = "";
                this.txt_UserFullName.Text = "";
                this.txt_Remark.Text = "";
                this.txt_user_Pwd.Text = "";
                this.comboBox1.Text = " --请选择--";
                this.txt_UserName.Text = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                this.txt_UserFullName.Text = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                this.txt_Remark.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                this.comboBox1.Text = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            }
            catch (Exception)
            {
            }
        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                Rectangle bounds = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
                TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), this.dataGridView1.RowHeadersDefaultCellStyle.Font, bounds, this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.panel1 = new Panel();
            this.groupBox3 = new GroupBox();
            this.btn_Cancel = new Button();
            this.btn_Add_Edit = new Button();
            this.comboBox1 = new ComboBox();
            this.txt_Remark = new TextBox();
            this.txt_UserFullName = new TextBox();
            this.txt_user_Pwd = new TextBox();
            this.txt_UserName = new TextBox();
            this.label5 = new Label();
            this.label4 = new Label();
            this.label3 = new Label();
            this.label1 = new Label();
            this.groupBox2 = new GroupBox();
            this.btn_ShouQuan = new Button();
            this.btn_ShanChu = new Button();
            this.btn_XiuGai = new Button();
            this.btn_TianJia = new Button();
            this.groupBox1 = new GroupBox();
            this.dataGridView1 = new DataGridView();
            this.Column1 = new DataGridViewTextBoxColumn();
            this.Column2 = new DataGridViewTextBoxColumn();
            this.Column3 = new DataGridViewTextBoxColumn();
            this.Column4 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn4 = new DataGridViewTextBoxColumn();
            this.panel1.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.panel1.Controls.Add(this.groupBox3);
            this.panel1.Controls.Add(this.groupBox2);
            this.panel1.Controls.Add(this.groupBox1);
            this.panel1.Location = new Point(0, 3);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x213, 0x19e);
            this.panel1.TabIndex = 0;
            this.groupBox3.Controls.Add(this.btn_Cancel);
            this.groupBox3.Controls.Add(this.btn_Add_Edit);
            this.groupBox3.Controls.Add(this.comboBox1);
            this.groupBox3.Controls.Add(this.txt_Remark);
            this.groupBox3.Controls.Add(this.txt_UserFullName);
            this.groupBox3.Controls.Add(this.txt_user_Pwd);
            this.groupBox3.Controls.Add(this.txt_UserName);
            this.groupBox3.Controls.Add(this.label5);
            this.groupBox3.Controls.Add(this.label4);
            this.groupBox3.Controls.Add(this.label3);
            this.groupBox3.Controls.Add(this.label1);
            this.groupBox3.Location = new Point(4, 0x13e);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new Size(0x20f, 90);
            this.groupBox3.TabIndex = 2;
            this.groupBox3.TabStop = false;
            this.btn_Cancel.Location = new Point(330, 0x41);
            this.btn_Cancel.Name = "btn_Cancel";
            this.btn_Cancel.Size = new Size(0x44, 0x17);
            this.btn_Cancel.TabIndex = 12;
            this.btn_Cancel.Text = "取消(&C)";
            this.btn_Cancel.UseVisualStyleBackColor = true;
            this.btn_Cancel.Click += new EventHandler(this.btn_Cancel_Click);
            this.btn_Add_Edit.Location = new Point(0xd1, 0x41);
            this.btn_Add_Edit.Name = "btn_Add_Edit";
            this.btn_Add_Edit.Size = new Size(70, 0x17);
            this.btn_Add_Edit.TabIndex = 10;
            this.btn_Add_Edit.Text = "确定(&O)";
            this.btn_Add_Edit.UseVisualStyleBackColor = true;
            this.btn_Add_Edit.Click += new EventHandler(this.btn_Add_Edit_Click);
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Items.AddRange(new object[] { "--请选择--", "管理员", "普通用户" });
            this.comboBox1.Location = new Point(0x70, 0x27);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new Size(100, 20);
            this.comboBox1.TabIndex = 9;
            this.comboBox1.Text = "  --请选择--";
            this.txt_Remark.Location = new Point(0x132, 0x26);
            this.txt_Remark.Name = "txt_Remark";
            this.txt_Remark.Size = new Size(0xa3, 0x15);
            this.txt_Remark.TabIndex = 8;
            this.txt_UserFullName.Location = new Point(0x133, 11);
            this.txt_UserFullName.Name = "txt_UserFullName";
            this.txt_UserFullName.Size = new Size(0x7b, 0x15);
            this.txt_UserFullName.TabIndex = 7;
            this.txt_user_Pwd.Location = new Point(0x54, 0x41);
            this.txt_user_Pwd.Name = "txt_user_Pwd";
            this.txt_user_Pwd.ReadOnly = true;
            this.txt_user_Pwd.Size = new Size(0x67, 0x15);
            this.txt_user_Pwd.TabIndex = 6;
            this.txt_user_Pwd.Text = "1234";
            this.txt_user_Pwd.UseSystemPasswordChar = true;
            this.txt_user_Pwd.Visible = false;
            this.txt_UserName.Location = new Point(0x70, 12);
            this.txt_UserName.Name = "txt_UserName";
            this.txt_UserName.Size = new Size(100, 0x15);
            this.txt_UserName.TabIndex = 5;
            this.label5.AutoSize = true;
            this.label5.Location = new Point(0xeb, 0x29);
            this.label5.Name = "label5";
            this.label5.Size = new Size(0x41, 12);
            this.label5.TabIndex = 4;
            this.label5.Text = "备注说明：";
            this.label4.AutoSize = true;
            this.label4.Location = new Point(0x39, 0x2a);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x35, 12);
            this.label4.TabIndex = 3;
            this.label4.Text = "权限组：";
            this.label3.AutoSize = true;
            this.label3.Location = new Point(0xdf, 0x11);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x4d, 12);
            this.label3.TabIndex = 2;
            this.label3.Text = "设计师姓名：";
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0x3a, 0x10);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x35, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "用户名：";
            this.groupBox2.Controls.Add(this.btn_ShouQuan);
            this.groupBox2.Controls.Add(this.btn_ShanChu);
            this.groupBox2.Controls.Add(this.btn_XiuGai);
            this.groupBox2.Controls.Add(this.btn_TianJia);
            this.groupBox2.Location = new Point(3, 0x149);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x20a, 0x2b);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.btn_ShouQuan.BackColor = SystemColors.Control;
            this.btn_ShouQuan.Location = new Point(440, 14);
            this.btn_ShouQuan.Name = "btn_ShouQuan";
            this.btn_ShouQuan.Size = new Size(0x4b, 0x17);
            this.btn_ShouQuan.TabIndex = 3;
            this.btn_ShouQuan.Text = "授权";
            this.btn_ShouQuan.UseVisualStyleBackColor = false;
            this.btn_ShouQuan.Visible = false;
            this.btn_ShouQuan.Click += new EventHandler(this.btn_ShouQuan_Click);
            this.btn_ShanChu.BackColor = SystemColors.Control;
            this.btn_ShanChu.Location = new Point(0x156, 14);
            this.btn_ShanChu.Name = "btn_ShanChu";
            this.btn_ShanChu.Size = new Size(0x4b, 0x17);
            this.btn_ShanChu.TabIndex = 2;
            this.btn_ShanChu.Text = "删除(&D)";
            this.btn_ShanChu.UseVisualStyleBackColor = false;
            this.btn_ShanChu.Click += new EventHandler(this.btn_ShanChu_Click);
            this.btn_XiuGai.BackColor = SystemColors.Control;
            this.btn_XiuGai.Location = new Point(0xee, 13);
            this.btn_XiuGai.Name = "btn_XiuGai";
            this.btn_XiuGai.Size = new Size(0x4b, 0x17);
            this.btn_XiuGai.TabIndex = 1;
            this.btn_XiuGai.Text = "修改(&E)";
            this.btn_XiuGai.UseVisualStyleBackColor = false;
            this.btn_XiuGai.Click += new EventHandler(this.btn_XiuGai_Click);
            this.btn_TianJia.BackColor = SystemColors.Control;
            this.btn_TianJia.Location = new Point(0x84, 13);
            this.btn_TianJia.Name = "btn_TianJia";
            this.btn_TianJia.Size = new Size(0x4b, 0x17);
            this.btn_TianJia.TabIndex = 0;
            this.btn_TianJia.Text = "添加(&A)";
            this.btn_TianJia.UseVisualStyleBackColor = false;
            this.btn_TianJia.Click += new EventHandler(this.btn_TianJia_Click);
            this.groupBox1.Controls.Add(this.dataGridView1);
            this.groupBox1.Location = new Point(4, 3);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(520, 0x135);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "用户管理";
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.BackgroundColor = Color.WhiteSmoke;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4 });
            this.dataGridView1.Location = new Point(4, 14);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowHeadersWidth = 30;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new Size(510, 0x121);
            this.dataGridView1.TabIndex = 0;
            this.dataGridView1.CellClick += new DataGridViewCellEventHandler(this.dataGridView1_CellClick);
            this.dataGridView1.RowPostPaint += new DataGridViewRowPostPaintEventHandler(this.dataGridView1_RowPostPaint);
            this.Column1.HeaderText = "用户名";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column2.HeaderText = "设计师姓名";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column3.HeaderText = "权限组";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column4.HeaderText = "备注说明";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Width = 180;
            this.dataGridViewTextBoxColumn1.HeaderText = "用户名";
            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
            this.dataGridViewTextBoxColumn2.HeaderText = "姓名";
            this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
            this.dataGridViewTextBoxColumn3.HeaderText = "权限组";
            this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
            this.dataGridViewTextBoxColumn4.HeaderText = "说明";
            this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
            this.dataGridViewTextBoxColumn4.Width = 180;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
           // base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x216, 0x1a2);
            base.Controls.Add(this.panel1);
//            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            this.MaximumSize = new Size(540, 450);
            this.MinimumSize = new Size(540, 450);
            base.Name = "SysUsers";
            base.StartPosition = FormStartPosition.WindowsDefaultBounds;
            this.Text = "用户管理";
            base.Load += new EventHandler(this.SysUsers_Load);
            this.panel1.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
        }

        private void SysUsers_Load(object sender, EventArgs e)
        {
            base.Height = 300;
        }
    }
}

